package cn.exrick.xboot.config.WebMvcConfig;

import cn.exrick.xboot.common.constant.CommonConstant;
import cn.exrick.xboot.modules.portalConfig.entity.PortalConfig;
import cn.exrick.xboot.modules.portalConfig.service.IPortalConfigService;
import cn.exrick.xboot.modules.portalConfig.serviceimpl.IPortalConfigServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

/**
 * njp add 配置静态资源映射地址的 20190823
 */
@Configuration
public class WebMvcConfiguration extends WebMvcConfigurerAdapter {
    @Autowired
    private  IPortalConfigService iPortalConfigService;

    private  static  String path=null;

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
       // registry.addResourceHandler(CommonConstant.IMAGE_PATH).addResourceLocations("file:D://image/");
        if(path==null){
            path= iPortalConfigService.selectPortalConfigByKey("upload").getValue();
        }
        registry.addResourceHandler(CommonConstant.IMAGE_PATH+"**").addResourceLocations("file:"+path);
        super.addResourceHandlers(registry);
    }


}

